/**
 * Created by Administrator on 2017/5/26 0026.
 */
$(function(){
    var userName = "shanmao"
    var product_info=[{
        "icon1src":"<img src='images/func1.png' width='36' height='36' style='display:inline-block;'>",
        "regType":"<span>有限公司注册</span>",
        "dic1":"<span>地区:北京市 海淀区</span>",
        "serversrc":"<img src='images/touxiang_01.jpg'  width='33' height='33' style='display:inline-block;' >",
        "serverName":"<span>刘梅哈</span>",
        "price1":"<span>488.00元<span>",
        "num1":"<span>1</span>",
        "sum2":"<span>488.00元<span>"
    },{
        "icon1src":"<img src='images/func2.png' width='36' height='36' style='display:inline-block;'>",
        "regType":"<span>开立银行公司帐户</span>",
        "dic1":"<span>地区:北京市 海淀区</span>",
        "serversrc":"<img src='images/touxiagn_02.jpg'  width='33' height='33' style='display:inline-block;'>",
        "serverName":"<span>郭美丞</span>",
        "price1":"<span>398.00元<span>",
        "num1":"<span>1</span>",
        "sum2":"<span>398.00元<span>"
    },{
        "icon1src":"<img src='images/func3.png' width='36' height='36' style='display:inline-block;'>",
        "regType":"<span>国税报到</span>",
        "dic1":"<span>地区:北京市 海淀区</span>",
        "serversrc":"<img src='images/touxiagn_03.jpg'  width='33' height='33' style='display:inline-block;'>",
        "serverName":"<span>刘璐璐</span>",
        "price1":"<span>0.00元<span>",
        "num1":"<span>1</span>",
        "sum2":"<span>0.00元<span>"
    },
        {
            "icon1src":"<img src='images/func4.png' width='36' height='36'  style='display:inline-block;'>",
            "regType":"<span>小规模记账</span>",
            "dic1":"<span>地区:北京市 海淀区</span>",
            "serversrc":"<img src='images/touxiagn_03.jpg'  width='33' height='33' style='display:inline-block;'>",
            "serverName":"<span>郭美丞</span>",
            "price1":"<span>398.00元<span>",
            "num1":"<span>1</span>",
            "sum2":"<span>398.00元<span>"
        },
        {
            "icon1src":"<img src='images/func3.png' width='36' height='36' style='display:inline-block;'>",
            "regType":"<span>地税报到</span>",
            "dic1":"<span>地区:北京市 海淀区</span>",
            "serversrc":"<img src='images/touxiagn_05.jpg' width='33' height='33' style='display:inline-block;'>",
            "serverName":"<span>郭美丞</span>",
            "price1":"<span>2752.00元<span>",
            "num1":"<span>1</span>",
            "sum2":"<span>2752.00元<span>"
        }
    ];
    var s_product_info =JSON.stringify(product_info);
    //创建一个名为shanmao  值 为 product_info的cokie
    $.cookie(userName,s_product_info);
    //读取cookie
    var count = $.cookie(userName);
    var countArray = JSON.parse(count);
    // console.log(countArray);
    for(var i = 0;i<countArray.length;i++){
       var $div =  $("<div class='clear dynamicDivParent'></div>");
        // console.log($div);
        for(var key in countArray[i]){
            var $span = $("<div style='float:left;'>"+countArray[i][key]+"</div>");
            $div.append($span);

        }
        $(".chanping").append($div);
        $(".number").text(i);
        $.cookie("number",i);
    }
    //计算总单价 和  总价
        $("#price").text( parseInt($(".chanping>div").children("div:eq(5)").children("span").text())*5+"元")
        $("#sum").text(parseInt($("#price").text())+"元");
    $("#totals").text($("#sum").text());
    //金额应付
    $("#amount").text($("#totals").text());
    //优惠券
     $(".ulli>li").each(function(index,ele){
         $(ele).on("click",function(){
            $(".ticket_inner").find("div").eq(index).css("display","block").siblings("div").css("display","none")
                $(this).addClass("active").siblings().removeClass("active");
         })
     })
    //添加数量
    var num=1;

    $("#plus_cut").children("li").eq(0).on("click",function(){

        var txt = $(".chanping>div").children("div:eq(6)").children("span").text();
        if(txt > 1){
            $(".chanping>div").each(function(index,ele){
                $(ele).children("div:eq(6)").children("span").text(
                    $(".chanping>div").eq(index).children("div:eq(6)").children("span").text()-0-num);
                //小计
                $(ele).children("div:eq(7)").children("span").text(
                    ($(".chanping>div").eq(index).children("div:eq(6)").children("span").text()-0)*488);
                $("#sum").text(3638*($(".chanping>div").eq(index).children("div:eq(6)").children("span").text()-0))
                //金额总计
                $("#totals").text($("#sum").text());
                //金额应付
                $("#amount").text($("#totals").text());
            })


       }
    })
    $("#plus_cut").children("li").eq(2).on("click",function(){
        $(".chanping>div").each(function(index,ele){
           $(ele).children("div:eq(6)").children("span").text(
                $(".chanping>div").eq(index).children("div:eq(6)").children("span").text()-0+num);
            //小计
            $(ele).children("div:eq(7)").children("span").text(
                ($(".chanping>div").eq(index).children("div:eq(6)").children("span").text()-0)*488);
            //总计
             $("#sum").text(3638*($(".chanping>div").eq(index).children("div:eq(6)").children("span").text()-0))

            //金额总计
            $("#totals").text($("#sum").text());
            //金额应付
            $("#amount").text($("#totals").text());
        })
    })

    //操作
    $("#operate").on("click",function(){
        $(".chanping").remove();
    })
    //
})
